<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of cookies
 *
 * @author Administrator
 */
class Cookies {
    public $expire;
    public $path;
    public $domain;
    
    /***
     * 设置作用域
     */
    function __construct()
    {
        if($this->expire==null){ $this->expire = time() + 86400; }
        if($this->path ==null){ $this->path = '/'; }
        if($this->domain ==null){ $this->domain = $_SERVER['HTTP_HOST']; }
    }

    /***
     * 设置cookies变量
     */
    function set($array)
    {
        foreach($array as $k=>$v)
        {
            setcookie($k,$v, $this->expire, $this->path, $this->domain);
        }
    }

    /***
     * 获取指定cookies值
     */
    function get($key)
    {
        return isset($_COOKIE[$key]) ? $_COOKIE[$key] : '';
    }
    
    /***
     * 删除指定cookies值
     */
    function del($key)
    {
        setcookie($_COOKIE[$key],'', time()-10, $this->path, $this->domain);
        unset($_COOKIE[$key]);
    }
    
    /***
     * 清空cookies
     */
    function clear()
    {
        foreach($_COOKIE as $k=>$v)
        {
            setcookie($k,'', time() - 10,$this->path,$this->domain);
        }
        unset($_COOKIE);
    }
}